/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.model.layers;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

public class LayerImage extends ALayer
{
    private static final int    M_SCALE_ALGORITHM = Image.SCALE_SMOOTH;
    
    private Image               m_img;
    private Image               m_originalImg;
    private int                 m_originalWidth;
    private int                 m_originalHeight;

    public LayerImage (String m_name)
    {
        super(m_name);
    }

    public void setScale (int width, int height)
    {
        Graphics2D      g2d;
        BufferedImage   bufferImg;
        
        bufferImg = new BufferedImage(m_originalWidth, m_originalHeight, M_DEFAULT_IMAGE_TYPE);
        
        g2d = bufferImg.createGraphics();
        g2d.drawImage(m_originalImg, M_DEFAULT_POSITION_X, M_DEFAULT_POSITION_Y, m_originalWidth, m_originalHeight, null);
        
        this.m_img      = bufferImg.getScaledInstance(width, height, M_SCALE_ALGORITHM);
        this.m_height   = height;
        this.m_width    = width;
        
        this.updateObservers();
    }

    @Override
    public void setM_width (int m_width)
    {
        super.setM_width(m_width);
        
        this.m_originalWidth = m_width;
    }

    @Override
    public void setM_height (int m_height)
    {
        super.setM_height(m_height);
        
        this.m_originalHeight = m_height;
    }

    public Image getM_img ()
    {
        return m_img;
    }

    public void setM_img (Image m_img)
    {
        this.m_originalImg  = m_img;
        this.m_img          = m_img;
    }

    @Override
    protected void drawLayer (Graphics2D g2d)
    {
        g2d.drawImage(this.getM_img(), this.getM_x(), this.getM_y(), null);
    }
}
